var myChart1 = echarts.init(document.getElementById('assets_liabilities'));



$('.cont').resize(function () {
  myChart1.resize()
  myChart2.resize()
  myChart3.resize()
  myChart4.resize()
  myChart5.resize()
})


$(function () {
  finance = 1;
  initfinanceData()
})

function initfinanceData() {
  var obj = {
    budgetYear: fullYear,
    budgetMonth: fullMonth,
    dept: fullDepartment,
    status: 2,
    chartPage: 50103
  }
  ApiGet('getdata', obj, function (e) {
    var json = JSON.parse(e);
    console.log(json, "jjjsssom")
    var chartData = json.items[0].charts;
    getquarterlyTrend(chartData[0].data)
    getproportionLiab(chartData[1].data) //资产负债占比
    trendQuarterly(chartData[2].data) //季度趋势
    getcashequivalent(chartData[2].data) //现金等价季度趋势
    getquarterlytotal(chartData[2].data) //利润总额季度趋势
  });
}
//资产负债占比
function getproportionLiab(data) {
  let zongfuzhai = (data[0].key01 * 100).toFixed(2)
  let zongzichan = (data[0].key02 * 100).toFixed(2)
  var assets_liabilities = {
    tooltip: {
      trigger: 'item',
      // formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    color: ['#165DFF', '#F1416C'],
    series: [{
      type: 'pie',
      radius: ['30%', '90%'],
      avoidLabelOverlap: false,
      label: {
        show: false,
        position: 'center'
      },
      itemStyle: {
        normal: {
          label: {
            position: 'inner',
            formatter: "{b}:{d}%"

          },
          labelLine: {
            show: false
          }
        },


      },
      data: [{
          value: zongzichan,
          name: '总资产'
        },
        {
          value: zongfuzhai,
          name: '总负债'
        }
      ],

    }]
  };
  myChart1.setOption(assets_liabilities);
}
//总数据
function getquarterlyTrend(data) {
  let zichan = data
  //总资产
  $(".totalAssets").text(pricefmt(zichan[0].key01));
  //总负债
  $(".totalLiabilities").text(pricefmt(zichan[0].key02));
  //总收入
  $(".totalRevenue").text(pricefmt(zichan[0].key03));
  //总利润
  $(".totalProfit").text(pricefmt(zichan[0].key04));
  //现金及等价物余额
  $(".xianjin").text(pricefmt(zichan[0].key05));
  //期初
  $(".qichu").text(pricefmt(zichan[0].key06));
  //现金及现金等价物净增加额
  $(".jingzengjia").text(pricefmt(zichan[0].key07));
  //利润总额
  $(".lirunzong").text(pricefmt(zichan[0].key08));
  //净利润
  $(".jinglirun").text(pricefmt(zichan[0].key09));
  //存货周转率
  $(".cunhuozhouzhuan").text(pricefmt((zichan[0].key10 * 100).toFixed(2)));
  // $(".cunhuozhouzhuan").text((arr[16] * 100).toFixed(2));

  //应收账款及应收票据
  $(".yingshou").text(pricefmt(zichan[0].key11));

}
//季度趋势
function trendQuarterly(data) {
  console.log(data, "季度趋势")
  let zongshouru = []
  let zonglirun = []
  data.forEach((item) => {
    zongshouru.push(item.key02);
    zonglirun.push(item.key03);
  })
  // data.forEach((item) => {
  //   zongshouru.push((item.key02 / 10000).toFixed(2));
  //   zonglirun.push((item.key03 / 10000).toFixed(2));
  // })
  let xData = ['1', '2', '3', '4'];
  let legendData = ['总收入', '总利润'];
  let Data = [{
      name: '总收入',
      type: 'bar',
      barWidth: '20',
      barGap: 0,
      itemStyle: {
        color: '#4080FF'
      },
      data: zongshouru
    },
    {
      name: '总利润',
      type: 'bar',
      barWidth: '20',
      barGap: 0,
      itemStyle: {
        color: '#73D7A1'
      },
      data: zonglirun
    },

  ]
  have('quarterly_trend') ? oneYBarlegend('quarterly_trend', xData, legendData, Data) : ''
}

//现金及等价物余额 季度趋势
function getcashequivalent(data) {

  let dengjiawu = []
  data.forEach((item) => {
    dengjiawu.push(item.key04);
  })

  let xData = ['1', '2', '3', '4'];
  let legendData = ['现金及等价物余额'];
  let Data = [{
      name: '现金及等价物余额',
      type: 'bar',
      barWidth: '30',
      barGap: 0,
      itemStyle: {
        color: '#4080FF'
      },
      data: dengjiawu
    },

  ]
  have('cashe_quivalent') ? oneYBar('cashe_quivalent', xData, legendData, Data) : ''
}
//利润总额 季度趋势
function getquarterlytotal(data) {
  let lirunjidu = []
  data.forEach((item) => {
    lirunjidu.push(item.key05);
  })
  let xData = ['1', '2', '3', '4'];
  let legendData = ['利润总额 季度趋势'];
  let Data = [{
      name: '利润总额 季度趋势',
      type: 'bar',
      barWidth: '80',
      barGap: 0,
      itemStyle: {
        color: '#50CD89'
      },
      label: {
        show: true,
        position: 'top',


      },
      data: lirunjidu
    },

  ]
  have('quarterly_total') ? oneYBar('quarterly_total', xData, legendData, Data) : ''
}